package com.cx.dubbo;

import java.io.*;
import java.lang.reflect.Proxy;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @Author:chenxiaoyi
 * @Date:2021/1/20 16:21
 */
public class SocketProvider {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1", 9999);

            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
            while (true){
                String s = reader.readLine();
                writer.write(s);
                writer.write("\n");
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static <T> T getProxy(final Class<T> interfaceClass){
        return interfaceClass.cast(Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[]{interfaceClass}, (proxy, method, args) -> {
            System.out.println(interfaceClass.getName());
            System.out.println(method.getName());
            System.out.println(args);
            return "123";
        }));
    }

}
